<?php
/* @var $this UserController */
/* @var $model User */

$this->breadcrumbs=array(
	Yii::t('app', 'Sales management'),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-form form').submit(function(){
	$('#point-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<div class="page-header">
	<div class="page-title"><h3><?php echo Yii::t('app', 'Sales search' ) ?></h3></div>
	<div class="buttons">
		<a class="btn btn-primary" href="<?php echo $this->createUrl('export') ?>"><?php echo Yii::t('app', 'Export')?></a>
	</div>
</div>

<h1></h1>

<div class="search-form">
<?php $this->renderPartial('history/_search',array(
	'model'=>$model,
)); ?>
</div><!-- search-form -->

<?php $dataProvider = $model->search() ?>
<?php 
$total = 0;
foreach($dataProvider->data as $data) {
	$total += $data->price;
}
?>
<table class="table table-striped table-condensed table-nobor" id="tabSum">
	<tr>
		<td><?php echo Yii::t('app', 'Total' ) ?>:</td>
		<td><?php echo $total ?></td>
	</tr>
</table>

<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'point-grid',
	'dataProvider'=>$dataProvider,
	'columns'=>array(
		array(
			// 'header'=>Yii::t('app', 'Actions'),
			'class'=>'CButtonColumn',
			'template'=>'{detail}',
			'buttons'=>array(
				'detail' => array(
					'label'=>Yii::t('app', 'View Detail'),
					'url'=>'Yii::app()->createAbsoluteUrl("admin/user/update", array("id"=>$data->user->id))',
					'options'=>array('class'=>'btn btn-info'),
				),
			),
			'headerHtmlOptions'=>array('class'=>'span2'),
		),
		array(
			'name' => 'user_id',
			'value' => '$data->user->nickname',
		),
		array(
			'header' => Yii::t('app', 'Profile ID'),
			'value' => '$data->user->profile_id',
		),
		'created_time:time',
		array(
			'name' => 'point_package_id',
			'value' => '$data->package->name',
		),
		'price',
	),
	'itemsCssClass'=>'table table-bordered table-hover',
	'cssFile'=>false,
	'afterAjaxUpdate' => 'updateSummary',
)); ?>
<script>
function updateSummary(id,data) {
	$('#tabSum').html($(data).find('#tabSum').html());
}
</script>